﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Business.IFace;
using MB.Orm.DB;
using Public.DataAccess;
using MB.RuleBase.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace Business
{
    public class BPickBatch
    {
        public List<BatchNumberInfo> GetPickBatchInfoList(int pageIndex, int pageSize, out int total, params object[] parValues)
        {
            using (var DbScope = new OperationDatabaseScope(new OperationDatabaseContext("NewWeb")))
            {
                List<BatchNumberInfo> list = PagedDatabaseExcuteByXmlHelper.NewInstance.GetPagedObjectsByXml3<BatchNumberInfo>
                                                ("PickBatch", "GetPickBatchInfoList", pageIndex, pageSize, out total, parValues);
                return list;
            }
        }
        public bool InsertPickBatchInfo(DbTransaction transaction, List<BatchNumberInfo> lstBatchNumberInfo)
        {
            try
            {
                if (lstBatchNumberInfo == null || lstBatchNumberInfo.Count <= 0) return false;

                using (MB.RuleBase.BulkCopy.IDbBulkExecute bulk = MB.RuleBase.BulkCopy.DbBulkExecuteFactory.CreateDbBulkExecute(transaction))
                {
                    bulk.WriteToServer("PickBatch", "InsertPickBatchInfo", lstBatchNumberInfo);
                }

                return true;
            }
            catch (Exception ex)
            {
                MB.Util.TraceEx.Write(ex.Message);
                return false;
            }
        }

        public int UpdatePickBatchInfo(string BATCHNUMBER, string BATCHDATE, int FLAG, string EDITOR, DateTime EDITDATE)
        {
            return MB.RuleBase.Common.DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQuery("PickBatch", "UpdatePickBatchInfo"
                , BATCHNUMBER, BATCHDATE, FLAG, EDITOR, EDITDATE);
        }
    }
}
